-- ==============================================================================================

--===============================================================================

CREATE OR REPLACE FUNCTION ZOEDEVOPS.ZOEFUN_WERROR_JSON(iv_value IN VARCHAR2)
    RETURN VARCHAR2
	
-- Created in 2019.06.18 by polarbears
-- Copyright (c) 20xx, CHINA and/or affiliates.
-- All rights reserved.
--	Name:
-- 		zoefun_getjson.sql
--	Description:
-- 		
--  Relation:
--      zoeUtility
--	Notes:
--		
--	修改 - （年-月-日） - 描述
--  

AS
    lv_error_content      VARCHAR2(4000);
    lv_sqlerrm            VARCHAR2(512);
    lv_error_type         VARCHAR2(64);
    lv_error_info_json    VARCHAR2(4000);
    ln_pos_prev         NUMBER;
    ln_pos              NUMBER;
BEGIN
    ln_pos := INSTR(iv_value,'E0F');
    lv_error_info_json := '{"ERROR_TYPE":"'||SUBSTR(iv_value,1,ln_pos-1)||'"';
    ln_pos_prev := ln_pos+3;
    ln_pos := INSTR(iv_value,'E0F',ln_pos_prev);
    lv_error_info_json :=  lv_error_info_json||',"ERROR_CONTENT":{"ERROR_PROGRAM":"'||SUBSTR(iv_value,ln_pos_prev,ln_pos-ln_pos_prev)||'"';
    ln_pos_prev := ln_pos+3;
    ln_pos := INSTR(iv_value,'E0F',ln_pos_prev);
    lv_error_info_json := lv_error_info_json||',"ERROR_CODE":"'||SUBSTR(iv_value,ln_pos_prev,ln_pos-ln_pos_prev)||'"';
    ln_pos_prev := ln_pos+3;
    ln_pos := INSTR(iv_value,'E0F',ln_pos_prev);
    lv_error_info_json := lv_error_info_json||',"ERROR_SQL":"'||SUBSTR(iv_value,ln_pos_prev,ln_pos-ln_pos_prev)||'"';
    ln_pos_prev := ln_pos+3;
    ln_pos := INSTR(iv_value,'E0F',ln_pos_prev);
    lv_error_info_json := lv_error_info_json||',"ERROR_DATE":"'||SUBSTR(iv_value,ln_pos_prev)||'"';
    lv_error_info_json := lv_error_info_json||'}}';
    RETURN lv_error_info_json;
END ZOEFUN_WERROR_JSON;
/

